package com.winteam.View;

import com.winteam.Bean.RoomType;
import com.winteam.Controler.Updata;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddRoomType extends JFrame {
    Updata ud=new Updata();//导入方法
    private JTextField textField_fjlx;
    private JTextField textField_fjbed;
    private JTextField textField_ysdj;
    private JTextField textField_zdjf;


    RoomType roomType = new RoomType();
    public  AddRoomType(){
        super.setTitle("添加房间类型");

        this.setBounds(0, 0, 500, 492);//设置大小
        this.setLocationRelativeTo(null);//让窗口在屏幕中间显示
        this.setResizable(true);//让窗口大小不可改变
        getContentPane().setLayout(null);


        JLabel label = new JLabel("\u65B0\u623F\u95F4\u7C7B\u578B");
        label.setBounds(14, 13, 81, 18);
        getContentPane().add(label);

        JLabel label_2 = new JLabel("房间类型");
        label_2.setBounds(104, 61, 86, 18);
        getContentPane().add(label_2);

        JLabel label_3 = new JLabel("房间单价");
        label_3.setBounds(104, 115, 86, 18);
        getContentPane().add(label_3);

        JLabel label_4 = new JLabel("钟点计费");
        label_4.setBounds(104, 168, 87, 18);
        getContentPane().add(label_4);

        JLabel label_6 = new JLabel("床位数量");
        label_6.setBounds(104, 216, 86, 18);
        getContentPane().add(label_6);

        textField_fjlx = new JTextField();//房间类型
        textField_fjlx.setBounds(213, 61, 186, 24);
        getContentPane().add(textField_fjlx);
        textField_fjlx.setColumns(10);

        textField_ysdj = new JTextField();//房间单价
        textField_ysdj.setBounds(213, 115, 186, 24);
        getContentPane().add(textField_ysdj);
        textField_ysdj.setColumns(10);

        textField_zdjf = new JTextField();//钟点计费
        textField_zdjf.setBounds(213, 168, 186, 24);
        getContentPane().add(textField_zdjf);
        textField_zdjf.setColumns(10);
        textField_fjbed = new JTextField();//床位数量
        textField_fjbed.setBounds(213, 216, 186, 24);
        getContentPane().add(textField_fjbed);
        textField_fjbed.setColumns(10);



        JButton button_1 = new JButton("取消");button_1.setIcon(new ImageIcon(this.getClass().getResource("img\\cancel.gif")));
        button_1.setBounds(279, 339, 113, 27);
        getContentPane().add(button_1);
        //点击按钮关闭窗口
        button_1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });





        JButton button = new JButton("保存");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
            }
        });
        button.setIcon(new ImageIcon(this.getClass().getResource("img\\save.gif")));
        button.setBounds(82, 339, 113, 27);
        getContentPane().add(button);


        //添加点击事件
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                roomType.setRoom_type(textField_fjlx.getText());
                roomType.setR_price( Integer.parseInt( textField_ysdj.getText().toString()));
                roomType.setR_hprice(Integer.parseInt( textField_zdjf.getText().toString()));
                roomType.setR_bed(Integer.parseInt(textField_fjbed.getText().toString()));
            //把得到的数据填到数据库里面
                if (ud.AddRoomType(roomType)==true) {
                    JOptionPane.showMessageDialog(null,"添加完成");
                }
             dispose();
            }
        });
    }

    public static void main(String[] args) {
        new AddRoomType().setVisible(true);
    }
}
